home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / debug / Blowup.lha / source / traphandler.asm < prev   
Assembly Source File  |  1998-04-18  |  3KB  |  95 lines

  1. *
  2. * $Id: traphandler.asm 1.4 1998/04/18 15:45:53 olsen Exp olsen $
  3. *
  4. * :ts=8
  5. *
  6. * Blowup -- Catches and displays task errors
  7. *
  8. * Written by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
  9. * Public Domain
  10. *
  11.  
  12.     include    "exec/execbase.i"
  13.     include    "exec/tasks.i"
  14.     include    "exec/macros.i"
  15.  
  16. *****************************************************************************
  17.  
  18.     section    text,code
  19.  
  20. *****************************************************************************
  21.  
  22.     xref    _ShowCrashInfo
  23.  
  24. *****************************************************************************
  25.  
  26.     xdef    _TrapHandler
  27.     xdef    @TrapHandler
  28.  
  29. _TrapHandler:
  30. @TrapHandler:
  31.  
  32.     move.l    a0,-(sp)        ; save A0, we are going to need it in a minute
  33.     move.l    usp,a0            ; as we are in supervisor mode this minute, this gets the user stack pointer
  34.     movem.l    d0-d7/a0-a7,-(a0)    ; push all registers on the user stack; A0 and A7 will need fixing
  35.     move.l    (sp)+,8*4(a0)        ; push the original contents of A0 into the stack
  36.     move.l    a0,d0            ; save this for later
  37.     add.l    #4*16,d0        ; fix the stack offset
  38.     move.l    d0,(8+7)*4(a0)        ; and push the correct user stack pointer into the stack
  39.  
  40.     move.l    _SysBase,a6        ; get the ExecBase pointer, we are going to need it in a minute
  41.  
  42.     move.l    (sp)+,d2        ; get the type of the trap
  43.     cmp.l    #3,d2            ; was it an address error?
  44.     bne.b    .no_address_error    ; skip the following if it isn't
  45.  
  46.     move.w    AttnFlags(a6),d0
  47.     andi.w    #AFF_68010,d0        ; is this a plain 68k machine?
  48.     bne.b    .no_68k            ; skip the following if it isn't
  49.  
  50.     addq.l    #8,sp            ; skip the extra information the 68k puts into
  51.                     ; the address error exception frame
  52.  
  53. .no_address_error:
  54. .no_68k:
  55.     moveq    #0,d3
  56.     move.w    (sp)+,d3        ; get the copy of the status register
  57.     move.l    (sp),a2            ; get the program counter of the offending command
  58.  
  59.     move.l    SysStkUpper(a6),sp    ; get rid of the exception stack frame by using
  60.                     ; the upper bound of the supervisor stack; this
  61.                     ; is faster than walking through the entire
  62.                     ; stack frame in order to find out how long it is
  63.  
  64.     move.l    a0,usp            ; now get the user stack pointer ready...
  65.     andi.w    #(~$2000),sr        ; and switch back into user mode
  66.  
  67.     sub.l    a1,a1            ; find the current task
  68.     JSRLIB    FindTask        
  69.     move.l    d0,a0
  70.     move.l    TaskTrapCode(a6),a1    ; get the exec default trap handler
  71.     move.l    a1,TC_TRAPCODE(a0)    ; patch the task trap handler so our code
  72.                     ; will end in a well-defined state should
  73.                     ; the crash info dump trigger another
  74.                     ; trap; we don't want to rerun our custom
  75.                     ; trap handler recursively
  76.  
  77.     move.l    d2,d0            ; D0 = trap type
  78.     move.l    a2,d1            ; D1 = program counter
  79.     move.l    d3,d2            ; D2 = status register
  80.     move.l    sp,a0            ; A0 = register dump (d0-d7/a0-a7)
  81.  
  82.     bra    _ShowCrashInfo        ; show what we got; this call never returns
  83.  
  84. *****************************************************************************
  85.  
  86.     section    data,data
  87.  
  88. *****************************************************************************
  89.  
  90.     xref    _SysBase
  91.  
  92. *****************************************************************************
  93.  
  94.     end
  95.